//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************

#ifndef PrimaryGeneratorAction_h
#define PrimaryGeneratorAction_h 1

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

#include "G4Event.hh"
#include "G4ParticleGun.hh"
#include "G4ThreeVector.hh"
#include "G4VUserPrimaryGeneratorAction.hh"
#include "globals.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

class PrimaryGeneratorMessenger;
class DetectorConstruction;

class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
{
public:
    // The constructor defines a ParticleGun object, which allows
    // shooting a beam of particles through the experimental set-up.
    PrimaryGeneratorAction(DetectorConstruction* pDet);

    //The destructor. It deletes the ParticleGun.
    ~PrimaryGeneratorAction() override;

    //It reads the parameters of the primary particles.
    //Generates the primary event via the ParticleGun method.
    void GeneratePrimaries(G4Event* anEvent) override;

    //Get/Set methods
    void SetBeamEnergy(G4double val);

    inline void SetBeamSigmaE(G4double val) { _fSigmaE = val; };
    inline void SetBeamX(G4double val) { _fX0 = val; };
    inline void SetBeamY(G4double val) { _fY0 = val; };
    inline void SetBeamZ(G4double val) { _fZ0 = val; };
    inline void SetBeamSigmaX(G4double val) { _fSigmaX = val; };
    inline void SetBeamSigmaY(G4double val) { _fSigmaY = val; };
    inline void SetBeamSigmaZ(G4double val) { _fSigmaY = val; };
    inline void SetSigmaTheta(G4double val) { _fSigmaTheta = val; };
    inline void SetVerbose(G4int val) { _fVerbose = val; };
    inline void SetDisTypeXY(const G4String& type) { _fDisTypeXY = type; };
    inline void SetDisTypeE(const G4String& type) { _fDisTypeE = type; };
    inline void SetDisTypeTheta(const G4String& type) { _fDisTypeTheta = type; };  //2022.10.18
    inline void SetSpotDeltaY(G4double val) { _fSpotDeltaY = val; };               //2023.6.20, for QA test

    inline G4ThreeVector RotationMatrix(G4ThreeVector& locPos, G4ThreeVector& Rotx, G4ThreeVector& Roty, G4ThreeVector& Rotz) const;

    G4bool GetVerbose() const { return _fVerbose; }

private:
    void InitializeMe();

    PrimaryGeneratorAction& operator=(const PrimaryGeneratorAction& right);
    PrimaryGeneratorAction(const PrimaryGeneratorAction&);

    G4int _fVerbose;
    PrimaryGeneratorMessenger* _fMessenger;
    G4ParticleGun* _fParticleGun;
    DetectorConstruction* _fDetector;

    G4int _fCounter;
    G4double _fX0, _fY0, _fZ0;
    G4double _fSigmaX, _fSigmaY, _fSigmaZ;
    G4double _fRMax2;
    G4double _fSigmaE;
    G4double _fSigmaTheta;
    G4double _fEnergy;
    G4ThreeVector _fPosition;
    G4ThreeVector _fDirection;
    G4String _fDisTypeXY, _fDisTypeE;
    G4String _fDisTypeTheta;  //2022.10.18
    G4double _fSpotDeltaY;    //2023.6.20, for QA test

    void PrintSourceParameters();
};

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....

#endif